package com.jieshuibao.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jieshuibao.mapper.WishMapper;
import com.jieshuibao.mapper.WishcodeMapper;
import com.jieshuibao.model.db.Wish;
import com.jieshuibao.model.db.WishExample;

@Service
public class WishService{
	
	@Resource
	private WishMapper wishMapper;
	
	@Resource
	private RedisService redisService;
	
	@Resource
	private WishcodeMapper wishcodeMapper;
	
	public void addWish(Wish wish) {
		wishMapper.insertSelective(wish);
	}
	
	public void delWishById(String id) {
		wishMapper.deleteByPrimaryKey(id);
	}
	
	public void updateWish(Wish wish) {
		wishMapper.updateByPrimaryKeySelective(wish);
	}
	
	public Wish getWishById(String id) {
		return wishMapper.selectByPrimaryKey(id);
	}
	
	public List<Wish> getPageWish(WishExample wishExample) {
		return wishMapper.selectPage(wishExample);
	}
	
	public List<Wish> getWishsByExample(WishExample wishExample){
		return wishMapper.selectByExample(wishExample);
	}
	public int countWish(WishExample wishExample) {
		return wishMapper.countByExample(wishExample);
	}
	
	public void getwishCode(String key,int buyCount) {
//		String string = redisService.get(key);
//		for (int i = 0; i < buyCount; i++) {
//			redisService.incrby(key);
//			String string2 = redisService.get(key);
//			Long incrby = redisService.getIncrby(key);
//			
//			Wishcode wishcode = new Wishcode();
//			wishcode.setBuywithId(wishBuyId);
//			
//		}
//	   
//	    return 0;
		for (int i = 0; i < buyCount; i++) {
			System.out.println("-------------");
			System.out.println(redisService.getIncrby(key));
		}
	}
	 class MyThread  implements Runnable {
		 
	        private String foo2;
	        
	        private int buyCount;
	        
	        
	       

	        public MyThread(String foo2, int buyCount) {
				super();
				this.foo2 = foo2;
				this.buyCount = buyCount;
				
			}



			public void run() {
	        	getwishCode(foo2,buyCount);
	        }
	    }
}
